/************************************************************************************/
/*  Program name CAPFNDIMP_RESPONIBILITY_TL.sql                                     */
/*  Creater:  WONG Wing Kin (PCCW - UniHub)                                         */
/*************   History   *************************                                */
/* 30 NOV, 2005   WONG Wing Kin         First created                               */
/************************************************************************************/
SET SERVEROUTPUT ON SIZE 1000000;

--ALTER TRIGGER HR_ALL_ORGANIZATION_095639_WHO DISABLE;

DECLARE
	lv_Prog_ID		VARCHAR2(100)	:=	'CAPFNDIMP_RESPONIBILITY_TL';

	lv_Scc_Count	NUMBER			:=	0;
	lv_Err_Count	NUMBER			:=	0;
	lv_Err_Msg		VARCHAR2(500)	:=	'No Error';

	CURSOR Cur_F IS
	SELECT
		*
	FROM
		CRST_FND_RESPONSIBILITY_TL;

	lv_Next_Seq_ID	NUMBER;

BEGIN
	
	UPDATE
		FND_RESPONSIBILITY_TL
	SET
		RESPONSIBILITY_NAME	=	CAPBRIMP_MAPPING.RenameStr(SUBSTR(RESPONSIBILITY_NAME,1,4),RESPONSIBILITY_NAME)
	WHERE	Responsibility_ID	IN	(
								SELECT
									Responsibility_ID
								FROM
									CRST_FND_RESPONSIBILITY_TL
								);
	
	FOR C1 IN Cur_F LOOP
		BEGIN
			INSERT INTO FND_RESPONSIBILITY_TL
			VALUES
			(
			C1.APPLICATION_ID,
			CAPBRIMP_MAPPING.GetFNDRespIDMapping(C1.RESPONSIBILITY_ID),		--RESPONSIBILITY_ID,
			C1.LANGUAGE,
			C1.RESPONSIBILITY_NAME,
			CAPBRIMP_COMMON.GetUser(C1.CREATED_BY_NAME),					--CREATED_BY,
			C1.CREATION_DATE,
			CAPBRIMP_COMMON.GetUser(C1.LAST_UPDATED_BY_NAME),				--LAST_UPDATED_BY,
			C1.LAST_UPDATE_DATE,
			C1.LAST_UPDATE_LOGIN,
			C1.DESCRIPTION,
			C1.SOURCE_LANG
			);
		EXCEPTION
			WHEN OTHERS THEN
				DBMS_OUTPUT.Put_Line(SQLERRM);
				lv_Err_Count	:=	lv_Err_Count + 1;
		END;
		lv_Scc_Count	:=	lv_Scc_Count	+	1;
	END LOOP;

	IF	lv_Err_Count	>	0	THEN
		ROLLBACK;
	END IF;

	INSERT INTO CAPCNV_LOG(
		PROG_ID,
		PROCESS_DATE,
		RECORD_PROCESSED,
		RECORD_REJECTED,
		RECORD_EXTRACTED,
		ERR_MSG
	) VALUES (
		lv_Prog_ID,
		SYSDATE,
		lv_Scc_Count,
		lv_Err_Count,
		lv_Scc_Count-lv_Err_Count,
		lv_Err_Msg
	);

	COMMIT;
END;
/

--ALTER TRIGGER HR_ALL_ORGANIZATION_095639_WHO ENABLE;
